﻿using System;
using System.Collections.Generic;

/*
 * Write a program that extracts from a given text all dates that match
 * the format DD.MM.YYYY. Display them in the standard date format for Canada.
 */

namespace ExtractDates
{
    class ExtractDates
    {
        static bool AreDigits(string text, int startIndex, int lenght)
        {
            for (int index = startIndex, lengthForCheck = startIndex + lenght; index < lengthForCheck; index++)
            {
                if (!char.IsDigit(text[index]))
                {
                    return false;
                }
            }
            return true;
        }

        static bool IsDot(char character)
        {
            return character == '.';
        }

        static List<string> DateExtractor(string text)
        {
            List<string> dates = new List<string>();

            for (int index = 0, length = text.Length - 9; index < length; index++)
            {
                if (AreDigits(text, index, 2) && IsDot(text[index + 2]) && AreDigits(text, index + 3, 2) && IsDot(text[index + 5]) && AreDigits(text, index + 6, 4))
                {
                    dates.Add(text.Substring(index, 10));
                }
            }

            return dates;
        }

        static void Main()
        {
            List<string> result = DateExtractor("11.11.1111, 1.1.1, 27.2007 06.05.1992 01.06.2013");

            foreach (string date in result)
            {
                Console.WriteLine(date);
            }
        }
    }
}
